<template>
  <div class="basicMsg-content">
    <Title name="基础信息" :line="false">
      <el-row>
        <el-col :span="12">
          <aps-form
            :config="apsForm.formConfig"
            :model="apsForm.formData"
            :formRef="apsForm.formRef"
            :labelWidth="apsForm.labelWidth"
            ref="basicform"
          ></aps-form>
        </el-col>
        <el-col :span="12" class="button-area">
          <!-- <el-button
            type="primary"
            size="small"
            :plain="openEdit"
            @click="handlerSuborOpen"
          >
            {{ openEdit ? "确认" : "编辑" }}
          </el-button> -->
        </el-col>
      </el-row>
    </Title>
    <Title name="拓展信息" :line="false" style="margin-top: 20px">
      <el-row>
        <el-col :span="24">
          <aps-form
            :config="apsForm1.formConfig"
            :model="apsForm1.formData"
            :formRef="apsForm1.formRef"
            :labelWidth="apsForm1.labelWidth"
            ref="expandform"
          ></aps-form>
        </el-col>
      </el-row>
    </Title>
    <div style="height: 20px; width: 100%"></div>
  </div>
</template>

<script>
import Title from "@/components/Title";
import { typeAndLabelLv2Code2 } from "@/api/system/dict/data";
import {
  getByDeptId,
  postInstitution,
  putInstitution,
  getUserListByDept,
} from "@/api/departmental/index";
export default {
  name: "basicMsg",
  props: {},
  components: {
    Title,
  },
  dicts: ["organization_type", "quota_category", "provincial_assessment"],
  props: {
    chosedeptId: {
      type: [Number, String],
      default: "",
      require: false,
    },
    chosedeptName: {
      type: String,
      default: "",
      require: false,
    },
  },
  data() {
    return {
      info: {
        createTime: "",
        headOfUnitName: "",
        statisticsPersonName: "",
      },
      deptId: 0,
      deptName: "",
      showDeptArr: [],
      openEdit: false, // 是否开启编辑模式
      quotaCategoryArr: [], // 能耗定额类别数据集合
      quotaLevelAllArr: [], // 定额级别集合的集合
      chosequotaLevel: [], // 选中的定额级别集合
      deptPeopleArr: [], // 部门下用户集合
      isAddorEdit: true, // 为新增还是修改 true 修改； false 新增
      editID: null,
      apsForm: {
        formRef: "basicform",
        formData: {},
        labelWidth: "160px",
        formConfig: {
          formAttr: {
            // inline: true,
            "label-position": "right",
            size: "small",
            bsColumn: {
              col: 1,
              middle: true,
            },
            rules: {
              unifiedSocialCreditCode: [
                {
                  required: true,
                  message: " ",
                  trigger: "blur",
                },
                {
                  validator: function (rule, value, callback) {
                    let reg = new RegExp(
                      "^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$"
                    );
                    if (!reg.test(value)) {
                      callback("请勿输入特殊字符，且不能以下划线开头和结尾");
                    } else {
                      callback();
                    }
                  },
                  trigger: "blur",
                },
              ],
              organizationType: [
                {
                  required: true,
                  message: " ",
                  trigger: "change",
                },
              ],
              quotaCategory: [
                {
                  required: true,
                  message: " ",
                  trigger: "change",
                },
              ],
              quotaLevel: [
                {
                  required: true,
                  message: " ",
                  trigger: "change",
                },
              ],
              provincialAssessmentArr: [
                {
                  required: true,
                  message: " ",
                  trigger: "change",
                },
              ],
              industryCode: [
                {
                  required: false,
                  message: " ",
                  trigger: "change",
                },
              ],
              companyAddressProvince: [
                {
                  required: true,
                  message: " ",
                  trigger: "blur",
                },
                {
                  validator: function (rule, value, callback) {
                    let reg = new RegExp(
                      "^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$"
                    );
                    if (!reg.test(value)) {
                      callback("请勿输入特殊字符，且不能以下划线开头和结尾");
                    } else {
                      callback();
                    }
                  },
                  trigger: "blur",
                },
              ],
            },
          },
          properties: {
            // parentDept: {
            //   label: "上级单位",
            //   render: (h) => {
            //     let that = this;
            //     let arr = [...that.showDeptArr];
            //     // 数据严谨处理,处理后端数据异常情况
            //     let valNum = that.$refs?.basicform?.getFieldsValue().parentDept;
            //     let a = [
            //       h(
            //         "el-select",
            //         {
            //           attrs: {
            //             placeholder: "请选择上级单位",
            //             value: valNum,
            //             clearable: true,
            //             disabled: true,
            //           },
            //           props: ["value"],
            //           on: {
            //             change: (value) => {
            //               that.$refs?.basicform?.setFieldValue(
            //                 "parentDept",
            //                 value
            //               );
            //               that.$forceUpdate();
            //             },
            //           },
            //         },
            //         [
            //           arr.map((item) => {
            //             let { label, value } = item;
            //             return h("el-option", {
            //               props: {
            //                 label,
            //                 value: value,
            //                 key: value,
            //               },
            //             });
            //           }),
            //         ]
            //       ),
            //     ];
            //     return h("div", a);
            //   },
            // },
            companyName: {
              label: "单位名称",
              render: (h) => {
                let that = this;
                let arr = [...that.showDeptArr];
                // 数据严谨处理,处理后端数据异常情况
                let valNum =
                  that.$refs?.basicform?.getFieldsValue().companyName;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "",
                        value: valNum,
                        clearable: true,
                        disabled: true,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.basicform?.setFieldValue(
                            "companyName",
                            value
                          );
                          that.$forceUpdate();
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: value,
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
            unifiedSocialCreditCode: {
              label: "统一社会信用代码",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            organizationType: {
              label: "机构类型",
              typeName: "el-select",
              render: (h) => {
                let that = this;
                let arr = [];
                that.dict?.type?.organization_type.some((item) => {
                  arr.push(item);
                });
                // 数据严谨处理,处理后端数据异常情况
                let valNum =
                  that.$refs?.basicform?.getFieldsValue().organizationType;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "",
                        value: valNum,
                        disabled: !that.openEdit,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.basicform?.setFieldValue(
                            "organizationType",
                            value
                          );
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: value,
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
            quotaCategory: {
              label: "能耗定额类别",
              typeName: "el-select",
              render: (h) => {
                let that = this;
                let arr = [...that.quotaCategoryArr];
                // 数据严谨处理,处理后端数据异常情况
                let valNum =
                  that.$refs?.basicform?.getFieldsValue().quotaCategory;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "",
                        value: valNum,
                        disabled: !that.openEdit,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.basicform?.setFieldValue(
                            "quotaCategory",
                            value
                          );
                          that.$refs?.basicform?.setFieldValue(
                            "quotaLevel",
                            null
                          );
                          let choseindex;
                          that.quotaCategoryArr.map((item, index) => {
                            if (item.value === value) {
                              choseindex = index;
                            }
                          });
                          that.chosequotaLevel =
                            that.quotaLevelAllArr[choseindex];
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: value,
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
            quotaLevel: {
              label: "定额级别",
              typeName: "el-select",
              render: (h) => {
                let that = this;
                let arr = [...that.chosequotaLevel];
                // 数据严谨处理,处理后端数据异常情况
                let valNum = that.$refs?.basicform?.getFieldsValue().quotaLevel;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "",
                        value: valNum,
                        disabled: !that.openEdit,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.basicform?.setFieldValue(
                            "quotaLevel",
                            value
                          );
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: value,
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
            provincialAssessmentArr: {
              label: "单位创建类型:",
              typeName: "el-select",
              render: (h) => {
                let that = this;
                let arr = [];
                that.dict?.type?.provincial_assessment.some((item) => {
                  arr.push(item);
                });
                // 数据严谨处理,处理后端数据异常情况
                let valNum =
                  that.$refs?.basicform?.getFieldsValue()
                    .provincialAssessmentArr;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "",
                        value: valNum,
                        disabled: !that.openEdit,
                        multiple: true,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.basicform?.setFieldValue(
                            "provincialAssessmentArr",
                            value
                          );
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: value,
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
            industryCode: {
              label: "行业代码",
              typeName: "el-select",
              render: (h) => {
                let that = this;
                let arr = [];
                // 数据严谨处理,处理后端数据异常情况
                let valNum =
                  that.$refs?.basicform?.getFieldsValue().industryCode;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "",
                        value: valNum,
                        disabled: true,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.basicform?.setFieldValue(
                            "industryCode",
                            value
                          );
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: value,
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
            greenElectricity: {
              label: "绿电(kwh):",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            carbonSink: {
              label: "碳汇(tCO2):",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            companyAddressProvince: {
              label: "单位地址",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
              maxlength: 100,
            },
            remarks: {
              label: "备注",
              typeName: "el-input",
              type: "textarea",
              rows: 4,
              maxlength: 200,
              placeholder: "",
              disabled: true,
            },
          },
        },
      },
      apsForm1: {
        formRef: "expandform",
        formData: {},
        labelWidth: "160px",
        formConfig: {
          formAttr: {
            // inline: true,
            "label-position": "right",
            size: "small",
            bsColumn: {
              col: 2,
              middle: true,
            },
            rules: {
              statisticsLeaderId: [
                {
                  required: true,
                  message: " ",
                  trigger: "change",
                },
              ],
              statisticsLeaderMobilePhone: [
                {
                  required: true,
                  pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                  message: " ",
                  trigger: "blur",
                },
              ],
              statisticsLeaderFax: [
                {
                  required: false,
                  pattern: /^(\d{3,4}-)?\d{7,8}$/,
                  message: " ",
                  trigger: "blur",
                },
              ],
              statisticsLeaderEmail: [
                {
                  required: false,
                  pattern:
                    /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
                  message: " ",
                  trigger: "blur",
                },
              ],
              statisticsLeaderPostCode: [
                {
                  required: false,
                  pattern: /^[1-9][0-9]{5}$/,
                  message: " ",
                  trigger: "blur",
                },
              ],
              headOfUnitId: [
                {
                  required: true,
                  message: " ",
                  trigger: "change",
                },
              ],
              headOfUnitPhoneNumber: [
                {
                  required: false,
                  pattern:
                    /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/,
                  message: " ",
                  trigger: "blur",
                },
              ],
              headOfUnitMobilePhone: [
                {
                  required: true,
                  pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                  message: " ",
                  trigger: "blur",
                },
              ],
              statisticsPersonId: [
                {
                  required: true,
                  message: " ",
                  trigger: "change",
                },
              ],
              statisticsPersonPhoneNumber: [
                {
                  required: false,
                  pattern:
                    /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/,
                  message: " ",
                  trigger: "blur",
                },
              ],
              statisticsPersonMobilePhone: [
                {
                  required: true,
                  pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                  message: " ",
                  trigger: "blur",
                },
              ],
            },
          },
          properties: {
            statisticsLeaderId: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "统计负责人",
              render: (h) => {
                let that = this;
                let arr = [...that.deptPeopleArr];
                // 数据严谨处理,处理后端数据异常情况
                let valNum =
                  that.$refs?.expandform?.getFieldsValue().statisticsLeaderId;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "",
                        value: valNum,
                        disabled: !that.openEdit,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.expandform?.setFieldValue(
                            "statisticsLeaderId",
                            value
                          );
                          that.$forceUpdate();
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: value,
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
            tips: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "_",
              typeName: "aps-des",
            },
            statisticsLeaderMobilePhone: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "手机",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            statisticsLeaderFax: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "传真号码",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            statisticsLeaderEmail: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "电子邮箱",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            statisticsLeaderPostCode: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "邮政编码",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            page1: {
              typeName: "el-page-header",
              style: `margin-left:-100px;color:rgb(0 137 255);display: flex;
                line-height: 0px;border-bottom: 2px solid #d1d1d1;
                padding-bottom: 8px;width:100%;height:0px;font-weight: 600;`,
              class: "aps-header1",
              bsColumn: {
                col: 1,
              },
              content: "",
            },
            headOfUnitId: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "单位负责人",
              render: (h) => {
                let that = this;
                let arr = [...that.deptPeopleArr];
                // 数据严谨处理,处理后端数据异常情况
                let valNum =
                  that.$refs?.expandform?.getFieldsValue().headOfUnitId;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "",
                        value: valNum,
                        disabled: !that.openEdit,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.expandform?.setFieldValue(
                            "headOfUnitId",
                            value
                          );
                          that.$forceUpdate();
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: value,
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
            headOfUnitPhoneNumber: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "电话",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            headOfUnitMobilePhone: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "手机",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            page2: {
              typeName: "el-page-header",
              style: `margin-left:-100px;;color:rgb(0 137 255);display: flex;
                line-height: 0px;border-bottom: 2px solid #d1d1d1;
                padding-bottom: 8px;width:100%;height:0px;font-weight: 600;`,
              class: "aps-header1",
              bsColumn: {
                col: 1,
              },
              content: "",
            },
            statisticsPersonId: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "统计员",
              render: (h) => {
                let that = this;
                let arr = [...that.deptPeopleArr];
                // 数据严谨处理,处理后端数据异常情况
                let valNum =
                  that.$refs?.expandform?.getFieldsValue().statisticsPersonId;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "",
                        value: valNum,
                        disabled: !that.openEdit,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.expandform?.setFieldValue(
                            "statisticsPersonId",
                            value
                          );
                          that.$forceUpdate();
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: value,
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
            statisticsPersonPhoneNumber: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "电话",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
            statisticsPersonMobilePhone: {
              bsColumn: {
                col: 3,
                middle: true,
              },
              label: "手机",
              typeName: "el-input",
              placeholder: "",
              disabled: true,
            },
          },
        },
      },
    };
  },
  created() {
    setTimeout(() => {
      this.userDeptjudge();
      this.gettypeAndLabelLv2Code2();
    }, 200);
  },
  mounted() {
    setTimeout(() => {
      this.$refs?.basicform?.setFieldValue("companyName", this.deptId);
      this.getPeopleList();
      setTimeout(() => {
        this.getDeptmsg();
      }, 200);
    }, 200);
  },
  methods: {
    getPeopleList() {
      this.deptPeopleArr = [];
      let params = {
        deptId: this.deptId,
      };
      getUserListByDept(params)
        .then((res) => {
          if (res.code === 700) {
            this.$message.warning(res.msg);
            return false;
          }
          let arr = res?.data ?? [];
          if (arr.length > 0) {
            arr.map((item) => {
              let obj = {
                label: item?.nickName ?? "未知用户昵称",
                value: item?.userId ?? 1,
              };
              this.deptPeopleArr.push(obj);
            });
          }
        })
        .catch(() => {
          // this.$message.error("系统错误,请联系管理员!200380");
        });
    },
    getDeptmsg() {
      let params = {
        deptId: this.deptId,
      };
      getByDeptId(params)
        .then((res) => {
          if (res.code === 700) {
            this.$message.warning(res.msg);
            return false;
          }
          let data = res?.data ?? {};
          if (Object.keys(data).length > 0) {
            this.isAddorEdit = true;
            this.editID = data?.id ?? 0;
            this.$refs?.basicform?.setFieldValue(
              "companyName",
              data?.companyName ?? null
            );
            this.$refs?.basicform?.setFieldValue(
              "unifiedSocialCreditCode",
              data?.unifiedSocialCreditCode ?? null
            );
            this.$refs?.basicform?.setFieldValue(
              "organizationType",
              data?.organizationType ?? null
            );
            this.$refs?.basicform?.setFieldValue(
              "quotaCategory",
              data?.quotaCategory ?? null
            );
            this.$refs?.basicform?.setFieldValue(
              "quotaLevel",
              data?.quotaLevel ?? null
            );
            let provincialAssessment = data?.provincialAssessment ?? "";
            let provincialAssessmentArr = [];
            if (provincialAssessment.length > 0) {
              provincialAssessmentArr = provincialAssessment.split(",");
            }
            this.$refs?.basicform?.setFieldValue(
              "provincialAssessmentArr",
              provincialAssessmentArr
            );
            this.$refs?.basicform?.setFieldValue(
              "industryCode",
              data?.industryCode ?? null
            );
            this.$refs?.basicform?.setFieldValue(
              "greenElectricity",
              data?.greenElectricity ?? null
            );
            this.$refs?.basicform?.setFieldValue(
              "carbonSink",
              data?.carbonSink ?? null
            );
            this.$refs?.basicform?.setFieldValue(
              "companyAddressProvince",
              data?.companyAddressProvince ?? null
            );
            this.$refs?.basicform?.setFieldValue(
              "remarks",
              data?.remarks ?? null
            );

            this.$refs?.expandform?.setFieldValue(
              "statisticsLeaderId",
              data?.statisticsLeaderId ?? null
            );
            this.$refs?.expandform?.setFieldValue(
              "statisticsLeaderMobilePhone",
              data?.statisticsLeaderMobilePhone ?? null
            );
            this.$refs?.expandform?.setFieldValue(
              "statisticsLeaderFax",
              data?.statisticsLeaderFax ?? null
            );
            this.$refs?.expandform?.setFieldValue(
              "statisticsLeaderEmail",
              data?.statisticsLeaderEmail ?? null
            );
            this.$refs?.expandform?.setFieldValue(
              "statisticsLeaderPostCode",
              data?.statisticsLeaderPostCode ?? null
            );

            this.$refs?.expandform?.setFieldValue(
              "headOfUnitId",
              data?.headOfUnitId ?? null
            );

            this.info.headOfUnitName = this.findName(
              data.headOfUnitId,
              this.deptPeopleArr
            );
            this.info.statisticsPersonName = this.findName(
              data.statisticsPersonId,
              this.deptPeopleArr
            );
            this.info.createTime = this.$route.query.createTime;
            console.log(this.info);
            this.$refs?.expandform?.setFieldValue(
              "headOfUnitPhoneNumber",
              data?.headOfUnitPhoneNumber ?? null
            );
            this.$refs?.expandform?.setFieldValue(
              "headOfUnitMobilePhone",
              data?.headOfUnitMobilePhone ?? null
            );

            this.$refs?.expandform?.setFieldValue(
              "statisticsPersonId",
              data?.statisticsPersonId ?? null
            );
            this.$refs?.expandform?.setFieldValue(
              "statisticsPersonPhoneNumber",
              data?.statisticsPersonPhoneNumber ?? null
            );
            this.$refs?.expandform?.setFieldValue(
              "statisticsPersonMobilePhone",
              data?.statisticsPersonMobilePhone ?? null
            );
            this.judegequotaCategoryArr();
          } else {
            this.isAddorEdit = false;
            this.$refs?.basicform?.setFieldsValue({});
            this.$refs?.expandform?.setFieldsValue({});
          }
        })
        .catch(() => {
          // this.$message.error("系统错误,请联系管理员!200370");
        });
    },
    findName(val, arr) {
      console.log(val, arr);
      if (!val) {
        return "";
      }
      let data = arr.find((item) => item.value == val);

      return data.label;
    },
    userDeptjudge() {
      let user = this.$store.state.user;
      if (this.chosedeptId) {
        this.deptId = this.chosedeptId;
        this.deptName = this.chosedeptName;
      } else {
        this.deptId = user.deptId ?? 0;
        this.deptName = user.deptName ?? "暂无单位";
      }
      this.showDeptArr = [
        {
          label: this.deptName,
          value: this.deptId,
        },
      ];
    },
    // 初始化定额级别
    judegequotaCategoryArr() {
      let falge = this.$refs?.basicform?.getFieldsValue().quotaCategory;
      let choseindex;
      this.quotaCategoryArr.map((item, index) => {
        if (item.value === falge) {
          choseindex = index;
        }
      });
      this.chosequotaLevel = this.quotaLevelAllArr[choseindex];
    },
    gettypeAndLabelLv2Code2() {
      this.quotaCategoryArr = [];
      this.quotaLevelAllArr = [];
      typeAndLabelLv2Code2("quota_category")
        .then((res) => {
          if (res.code === 700) {
            this.$message.warning(res.msg);
            return false;
          }
          let arr = res?.data ?? [];
          this.dictsDeal(this.quotaCategoryArr, arr, 1);
          if (arr.length > 0) {
            arr.map((item) => {
              this.dictsDeal(this.quotaLevelAllArr, item.children, 2);
            });
          }
        })
        .catch(() => {
          // this.$message.error("系统错误,请联系管理员!");
        });
    },
    dictsDeal(target, arr, falge) {
      let childrenArr = [];
      if (arr.length > 0) {
        arr.map((item) => {
          let obj = {
            label: item.dictLabel,
            value: item.dictValue,
          };
          if (falge === 1) {
            target.push(obj);
          } else {
            childrenArr.push(obj);
          }
        });
        if (falge === 2) {
          target.push(childrenArr);
        }
      }
    },
    // allChange(falge) {
    //   this.changeDisabled(
    //     this.apsForm.formConfig.properties.unifiedSocialCreditCode,
    //     falge
    //   );
    //   this.changeDisabled(
    //     this.apsForm.formConfig.properties.companyAddressProvince,
    //     falge
    //   );
    //   this.changeDisabled(this.apsForm.formConfig.properties.remarks, falge);
    //   this.changeDisabled(
    //     this.apsForm1.formConfig.properties.statisticsLeaderMobilePhone,
    //     falge
    //   );
    //   this.changeDisabled(
    //     this.apsForm1.formConfig.properties.statisticsLeaderFax,
    //     falge
    //   );
    //   this.changeDisabled(
    //     this.apsForm1.formConfig.properties.statisticsLeaderEmail,
    //     falge
    //   );
    //   this.changeDisabled(
    //     this.apsForm1.formConfig.properties.statisticsLeaderPostCode,
    //     falge
    //   );
    //   this.changeDisabled(
    //     this.apsForm1.formConfig.properties.headOfUnitPhoneNumber,
    //     falge
    //   );
    //   this.changeDisabled(
    //     this.apsForm1.formConfig.properties.headOfUnitMobilePhone,
    //     falge
    //   );
    //   this.changeDisabled(
    //     this.apsForm1.formConfig.properties.statisticsPersonPhoneNumber,
    //     falge
    //   );
    //   this.changeDisabled(
    //     this.apsForm1.formConfig.properties.statisticsPersonMobilePhone,
    //     falge
    //   );
    // },
    // changeDisabled(target, falge) {
    //   target.disabled = falge;
    // },
    // // 新增
    // add(data) {
    //   postInstitution(data)
    //     .then((res) => {
    //       if (res.code === 700) {
    //         this.$message.warning(res.msg);
    //         return false;
    //       }
    //       this.$message.success("操作成功");
    //       setTimeout(() => {
    //         this.openEdit = false;
    //         this.getDeptmsg();
    //         this.allChange(true);
    //       }, 200);
    //     })
    //     .catch(() => {
    //       // this.$message.error("系统错误,请联系管理员!200350");
    //     });
    // },
    // // 修改
    // edit(data) {
    //   putInstitution(data)
    //     .then((res) => {
    //       if (res.code === 700) {
    //         this.$message.warning(res.msg);
    //         return false;
    //       }
    //       this.$message.success("操作成功");
    //       setTimeout(() => {
    //         this.openEdit = false;
    //         this.getDeptmsg();
    //         this.allChange(true);
    //       }, 200);
    //     })
    //     .catch(() => {
    //       // this.$message.error("系统错误,请联系管理员!200360");
    //     });
    // },
    // // 确认或编辑按钮
    // handlerSuborOpen() {
    //   if (!this.openEdit) {
    //     this.openEdit = true;
    //     this.allChange(false);
    //   } else {
    //     // 提交表单
    //     const data = {
    //       ...this.$refs.basicform.getFieldsValue(),
    //       ...this.$refs.expandform.getFieldsValue(),
    //     };
    //     let num = 0;
    //     this.$refs.basicform.validate((valid) => {
    //       if (valid) {
    //         num++;
    //       }
    //     });
    //     this.$refs.expandform.validate((valid) => {
    //       if (valid) {
    //         num++;
    //       }
    //     });
    //     if (num != 2) {
    //       return false;
    //     }
    //     data.companyName = null;
    //     this.$modal
    //       .confirm("确认修改单位基本信息？")
    //       .then(() => {
    //         if (this.isAddorEdit) {
    //           data.id = this.editID;
    //           this.edit(data);
    //         } else {
    //           data.deptId = this.deptId;
    //           this.add(data);
    //         }
    //       })
    //       .catch(() => {
    //         this.$message({
    //           message: "取消修改",
    //         });
    //       });
    //   }
    // },
  },
};
</script>

<style lang="scss" scoped>
.basicMsg-content {
  margin-top: 20px;
}
::v-deep .aps-header1 {
  .el-page-header__left {
    visibility: hidden;
  }
}
.button-area {
  display: flex;
  justify-content: flex-end;
}
</style>
